1 module directx.d3d11shader; 2 ////////////////////////////////////////////////////////////////////////////// 3 // 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // 6 // File: D3D11Shader.h 7 // Content: D3D11 Shader Types and APIs 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 version(Windows): 12 version(Direct3D_11): 13 14 public import directx.d3dcommon; 15 16 alias D3D11_SHADER_VERSION_TYPE = int; 17 enum : D3D11_SHADER_VERSION_TYPE 18 { 19 D3D11_SHVER_PIXEL_SHADER = 0, 20 D3D11_SHVER_VERTEX_SHADER = 1, 21 D3D11_SHVER_GEOMETRY_SHADER = 2, 22 23 // D3D11 Shaders 24 D3D11_SHVER_HULL_SHADER = 3, 25 D3D11_SHVER_DOMAIN_SHADER = 4, 26 D3D11_SHVER_COMPUTE_SHADER = 5, 27 } 28 29 int D3D11_SHVER_GET_TYPE(T)(_Version) { 30 return (((_Version) >> 16) & 0xffff); 31 } 32 33 int D3D11_SHVER_GET_MAJOR(T)(_Version) { 34 return (((_Version) >> 4) & 0xf); 35 } 36 37 int D3D11_SHVER_GET_MINOR(T)(_Version) { 38 return (((_Version) >> 0) & 0xf); 39 } 40 41 alias D3D_RESOURCE_RETURN_TYPE D3D11_RESOURCE_RETURN_TYPE; 42 43 alias D3D_CBUFFER_TYPE D3D11_CBUFFER_TYPE; 44 45 struct _D3D11_SIGNATURE_PARAMETER_DESC 46 { 47 LPCSTR SemanticName; // Name of the semantic 48 UINT SemanticIndex; // Index of the semantic 49 UINT Register; // Number of member variables 50 D3D_NAME SystemValueType;// A predefined system value, or D3D_NAME_UNDEFINED if not applicable 51 D3D_REGISTER_COMPONENT_TYPE ComponentType;// Scalar type (e.g. uint, float, etc.) 52 BYTE Mask; // Mask to indicate which components of the register 53 // are used (combination of D3D10_COMPONENT_MASK values) 54 BYTE ReadWriteMask; // Mask to indicate whether a given component is 55 // never written (if this is an output signature) or 56 // always read (if this is an input signature). 57 // (combination of D3D10_COMPONENT_MASK values) 58 UINT Stream; // Stream index 59 } 60 alias _D3D11_SIGNATURE_PARAMETER_DESC D3D11_SIGNATURE_PARAMETER_DESC; 61 62 struct _D3D11_SHADER_BUFFER_DESC 63 { 64 LPCSTR Name; // Name of the constant buffer 65 D3D_CBUFFER_TYPE Type; // Indicates type of buffer content 66 UINT Variables; // Number of member variables 67 UINT Size; // Size of CB (in bytes) 68 UINT uFlags; // Buffer description flags 69 } 70 alias _D3D11_SHADER_BUFFER_DESC D3D11_SHADER_BUFFER_DESC; 71 72 struct _D3D11_SHADER_VARIABLE_DESC 73 { 74 LPCSTR Name; // Name of the variable 75 UINT StartOffset; // Offset in constant buffer's backing store 76 UINT Size; // Size of variable (in bytes) 77 UINT uFlags; // Variable flags 78 LPVOID DefaultValue; // Raw pointer to default value 79 UINT StartTexture; // First texture index (or -1 if no textures used) 80 UINT TextureSize; // Number of texture slots possibly used. 81 UINT StartSampler; // First sampler index (or -1 if no textures used) 82 UINT SamplerSize; // Number of sampler slots possibly used. 83 } 84 alias _D3D11_SHADER_VARIABLE_DESC D3D11_SHADER_VARIABLE_DESC; 85 86 struct _D3D11_SHADER_TYPE_DESC 87 { 88 D3D_SHADER_VARIABLE_CLASS Class; // Variable class (e.g. object, matrix, etc.) 89 D3D_SHADER_VARIABLE_TYPE Type; // Variable type (e.g. float, sampler, etc.) 90 UINT Rows; // Number of rows (for matrices, 1 for other numeric, 0 if not applicable) 91 UINT Columns; // Number of columns (for vectors & matrices, 1 for other numeric, 0 if not applicable) 92 UINT Elements; // Number of elements (0 if not an array) 93 UINT Members; // Number of members (0 if not a structure) 94 UINT Offset; // Offset from the start of structure (0 if not a structure member) 95 LPCSTR Name; // Name of type, can be NULL 96 } 97 alias _D3D11_SHADER_TYPE_DESC D3D11_SHADER_TYPE_DESC; 98 99 alias D3D_TESSELLATOR_DOMAIN D3D11_TESSELLATOR_DOMAIN; 100 101 alias D3D_TESSELLATOR_PARTITIONING D3D11_TESSELLATOR_PARTITIONING; 102 103 alias D3D_TESSELLATOR_OUTPUT_PRIMITIVE D3D11_TESSELLATOR_OUTPUT_PRIMITIVE; 104 105 struct _D3D11_SHADER_DESC 106 { 107 UINT Version; // Shader version 108 LPCSTR Creator; // Creator string 109 UINT Flags; // Shader compilation/parse flags 110 111 UINT ConstantBuffers; // Number of constant buffers 112 UINT BoundResources; // Number of bound resources 113 UINT InputParameters; // Number of parameters in the input signature 114 UINT OutputParameters; // Number of parameters in the output signature 115 116 UINT InstructionCount; // Number of emitted instructions 117 UINT TempRegisterCount; // Number of temporary registers used 118 UINT TempArrayCount; // Number of temporary arrays used 119 UINT DefCount; // Number of constant defines 120 UINT DclCount; // Number of declarations (input + output) 121 UINT TextureNormalInstructions; // Number of non-categorized texture instructions 122 UINT TextureLoadInstructions; // Number of texture load instructions 123 UINT TextureCompInstructions; // Number of texture comparison instructions 124 UINT TextureBiasInstructions; // Number of texture bias instructions 125 UINT TextureGradientInstructions; // Number of texture gradient instructions 126 UINT FloatInstructionCount; // Number of floating point arithmetic instructions used 127 UINT IntInstructionCount; // Number of signed integer arithmetic instructions used 128 UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used 129 UINT StaticFlowControlCount; // Number of static flow control instructions used 130 UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used 131 UINT MacroInstructionCount; // Number of macro instructions used 132 UINT ArrayInstructionCount; // Number of array instructions used 133 UINT CutInstructionCount; // Number of cut instructions used 134 UINT EmitInstructionCount; // Number of emit instructions used 135 D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; // Geometry shader output topology 136 UINT GSMaxOutputVertexCount; // Geometry shader maximum output vertex count 137 D3D_PRIMITIVE InputPrimitive; // GS/HS input primitive 138 UINT PatchConstantParameters; // Number of parameters in the patch constant signature 139 UINT cGSInstanceCount; // Number of Geometry shader instances 140 UINT cControlPoints; // Number of control points in the HS->DS stage 141 D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive; // Primitive output by the tessellator 142 D3D_TESSELLATOR_PARTITIONING HSPartitioning; // Partitioning mode of the tessellator 143 D3D_TESSELLATOR_DOMAIN TessellatorDomain; // Domain of the tessellator (quad, tri, isoline) 144 // instruction counts 145 UINT cBarrierInstructions; // Number of barrier instructions in a compute shader 146 UINT cInterlockedInstructions; // Number of interlocked instructions 147 UINT cTextureStoreInstructions; // Number of texture writes 148 } 149 alias _D3D11_SHADER_DESC D3D11_SHADER_DESC; 150 151 struct _D3D11_SHADER_INPUT_BIND_DESC 152 { 153 LPCSTR Name; // Name of the resource 154 D3D_SHADER_INPUT_TYPE Type; // Type of resource (e.g. texture, cbuffer, etc.) 155 UINT BindPoint; // Starting bind point 156 UINT BindCount; // Number of contiguous bind points (for arrays) 157 158 UINT uFlags; // Input binding flags 159 D3D_RESOURCE_RETURN_TYPE ReturnType; // Return type (if texture) 160 D3D_SRV_DIMENSION Dimension; // Dimension (if texture) 161 UINT NumSamples; // Number of samples (0 if not MS texture) 162 } 163 alias _D3D11_SHADER_INPUT_BIND_DESC D3D11_SHADER_INPUT_BIND_DESC; 164 165 166 ////////////////////////////////////////////////////////////////////////////// 167 // Interfaces //////////////////////////////////////////////////////////////// 168 ////////////////////////////////////////////////////////////////////////////// 169 170 mixin( uuid!(ID3D11ShaderReflectionType, "6E6FFA6A-9BAE-4613-A51E-91652D508C21") ); 171 interface ID3D11ShaderReflectionType 172 { 173 extern(Windows): 174 HRESULT GetDesc( 175 D3D11_SHADER_TYPE_DESC* pDesc); 176 177 ID3D11ShaderReflectionType GetMemberTypeByIndex( 178 UINT Index); 179 180 ID3D11ShaderReflectionType GetMemberTypeByName( 181 LPCSTR Name); 182 183 LPCSTR GetMemberTypeName( 184 UINT Index); 185 186 HRESULT IsEqual( 187 ID3D11ShaderReflectionType pType); 188 189 ID3D11ShaderReflectionType GetSubType(); 190 191 ID3D11ShaderReflectionType GetBaseClass(); 192 193 UINT GetNumInterfaces(); 194 195 ID3D11ShaderReflectionType GetInterfaceByIndex( 196 UINT uIndex); 197 198 HRESULT IsOfType( 199 ID3D11ShaderReflectionType pType); 200 201 HRESULT ImplementsInterface( 202 ID3D11ShaderReflectionType pBase); 203 } 204 alias ID3D11ShaderReflectionType LPD3D11SHADERREFLECTIONTYPE; 205 206 207 208 mixin( uuid!(ID3D11ShaderReflectionVariable, "51F23923-F3E5-4BD1-91CB-606177D8DB4C") ); 209 interface ID3D11ShaderReflectionVariable 210 { 211 extern(Windows): 212 HRESULT GetDesc( 213 D3D11_SHADER_VARIABLE_DESC* pDesc); 214 215 ID3D11ShaderReflectionType GetType(); 216 217 ID3D11ShaderReflectionConstantBuffer GetBuffer(); 218 219 UINT GetInterfaceSlot( 220 UINT uArrayIndex); 221 } 222 alias ID3D11ShaderReflectionVariable LPD3D11SHADERREFLECTIONVARIABLE; 223 224 225 226 227 mixin( uuid!(ID3D11ShaderReflectionConstantBuffer, "EB62D63D-93DD-4318-8AE8-C6F83AD371B8") ); 228 interface ID3D11ShaderReflectionConstantBuffer 229 { 230 extern(Windows): 231 HRESULT GetDesc( 232 D3D11_SHADER_BUFFER_DESC* pDesc); 233 234 ID3D11ShaderReflectionVariable GetVariableByIndex( 235 UINT Index); 236 237 ID3D11ShaderReflectionVariable GetVariableByName( 238 LPCSTR Name); 239 240 } 241 alias ID3D11ShaderReflectionConstantBuffer LPD3D11SHADERREFLECTIONCONSTANTBUFFER; 242 243 244 245 // The ID3D11ShaderReflection IID may change from SDK version to SDK version 246 // if the reflection API changes. This prevents new code with the new API 247 // from working with an old binary. Recompiling with the new header 248 // will pick up the new IID. 249 250 mixin( uuid!(ID3D11ShaderReflection, "8d536ca1-0cca-4956-a837-786963755584") ); 251 interface ID3D11ShaderReflection : IUnknown 252 { 253 extern(Windows): 254 HRESULT GetDesc( 255 D3D11_SHADER_DESC* pDesc); 256 257 ID3D11ShaderReflectionConstantBuffer GetConstantBufferByIndex( 258 UINT Index); 259 260 ID3D11ShaderReflectionConstantBuffer GetConstantBufferByName( 261 LPCSTR Name); 262 263 HRESULT GetResourceBindingDesc( 264 UINT ResourceIndex, 265 D3D11_SHADER_INPUT_BIND_DESC* pDesc); 266 267 HRESULT GetInputParameterDesc( 268 UINT ParameterIndex, 269 D3D11_SIGNATURE_PARAMETER_DESC* pDesc); 270 271 HRESULT GetOutputParameterDesc( 272 UINT ParameterIndex, 273 D3D11_SIGNATURE_PARAMETER_DESC* pDesc); 274 275 HRESULT GetPatchConstantParameterDesc( 276 UINT ParameterIndex, 277 D3D11_SIGNATURE_PARAMETER_DESC* pDesc); 278 279 ID3D11ShaderReflectionVariable GetVariableByName( 280 LPCSTR Name); 281 282 HRESULT GetResourceBindingDescByName( 283 LPCSTR Name, 284 D3D11_SHADER_INPUT_BIND_DESC* pDesc); 285 286 UINT GetMovInstructionCount(); 287 288 UINT GetMovcInstructionCount(); 289 290 UINT GetConversionInstructionCount(); 291 292 UINT GetBitwiseInstructionCount(); 293 294 D3D_PRIMITIVE GetGSInputPrimitive(); 295 296 BOOL IsSampleFrequencyShader(); 297 298 UINT GetNumInterfaceSlots(); 299 300 HRESULT GetMinFeatureLevel( 301 D3D_FEATURE_LEVEL* pLevel) ; 302 303 UINT GetThreadGroupSize( 304 UINT* pSizeX, 305 UINT* pSizeY, 306 UINT* pSizeZ); 307 308 } 309 alias ID3D11ShaderReflection LPD3D11SHADERREFLECTION;